import { computed } from "vue";
import type { TableProps } from "tdesign-vue-next";

import dayjs from "dayjs";
import { getValueBySelectData, newPrecision } from "@/utils/tools";
import { CURRENCY_LIST } from "@/common/constants";

export const creditColumns = computed(
  () =>
    [
      {
        colKey: "funderName",
        title: "资方主体",
        width: 200
      },
      {
        colKey: "funderGlobalMainPartName",
        title: "国外主体",
        width: 200
      },
      {
        colKey: "expiryDate",
        title: "截止日期",
        width: 200,
        cell: (h, props) => {
          return dayjs(props.row.expiryDate).format("YYYY-MM-DD");
        }
      },
      {
        colKey: "dateLimit",
        title: "期限",
        width: 200,
        cell: (h, props) => {
          return `${props.row.dateLimit} 日`;
        }
      },
      {
        colKey: "moneyUnit",
        title: "金额单位",
        width: 200,
        cell: (h, props) => {
          return getValueBySelectData(CURRENCY_LIST, props.row.moneyUnit);
        }
      },
      {
        colKey: "creditLimit",
        title: "信用额度",
        width: 200,
        cell: (h, props) => {
          return newPrecision(props.row.creditLimit, 2);
        }
      },
      {
        colKey: "creditUsed",
        title: "已用额度",
        width: 200,
        cell: (h, props) => {
          if (props.row.id === "") {
            return "--";
          }
          return newPrecision(props.row.creditUsed, 2);
        }
      }
    ] as TableProps["columns"]
);
